#ifndef XGE_XDEBUG_H_
#define XGE_XDEBUG_H_
#include "xge_common_config.h"
#include "xassert.h"
#include "xstring.h"
#include "xallstatic.h"

namespace xge{
  namespace xge_internal {
    void Spew( const char_t* spew_words );
  }// namespace xge_internal


  class Debug : public AllStatic {
  public:
    static void FatalExit( const char_t* msg );
    static void Break();
    static String GetLastErrorString( int* last_error_code ) ;
    static void GetLastErrorString( int* last_error_code , String* error_string );
    static void Error();
  };
}// namespace xge



// Unreachable branch
#ifdef _DEBUG
#define UNREACH_BRANCH(Str) XASSERT_SAY(false,_xT("Unreached Branch.\n%s.\n"),(Str))
#else
#define UNREACH_BRANCH(Str) __assume(0)
#endif
// Spew
#ifdef _DEBUG
#define SPEW(Str) xge::xge_internal::Spew((Str))
#else
#define SPEW(Str) (void)(0)
#endif


#ifdef _DEBUG

#define GUARD_FOR(InitialStatus,Testing,Step,BoundedTimes) for( size_t __generate_time_counter=0 , InitialStatus ; \
  ( XASSERT_SAY( ++_generate_time_counter < (BoundedTimes) , _xT("Guard for overpassing bounded times:%d.\n"),(BoundedTimes) ), (Testing) ); \
  (Step))

#else

#define GUARD_FOR(InitialStatus,Testing,Step,BoundedTimes) for( InitialStatus ; Testing ; Step )

#endif

#ifdef _DEBUG

#define GUARD_WHILE(Condition,BoundedTimes) \
  for( size_t __generate_time_counter = 0 ; ( XASSERT_SAY( ++__generate_time_counter < (BoundedTimes) , _xT("Guard while overpassing bounded times:%d.\n") ,(BoundedTimes) ) , Condition ) ; )

#else

#define GUARD_WHILE(Condition,BoundedTimes) \
  while(Condition)


#endif






#endif// XGE_XDEBUG_H_